<template>
  <div class="container">
    <div>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item>
              <!-- <el-radio v-model="form.radioData" label="日">按日期：</el-radio> -->
              <span>查询日期：</span>
              <el-date-picker
                v-model="form.valueDay"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="道路名称：">
              <el-input
                v-model="form.roadName"
                placeholder="请输入道路名称"
                clearable
                style="width: 200px"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="分组：">
              <el-select
                v-model="CLIENT_GROUP_NAME"
                placeholder="请选择分组"
                @change="groupchange"
              >
                <el-option
                  v-for="(item, index) in groupingList"
                  :value="item.CLIENT_GROUP_NAME"
                  :label="item.CLIENT_GROUP_NAME"
                  :key="index"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
      <el-row :gutter="0" style="margin-top: 20px; margin-bottom: 20px">
        <el-col :span="3" :offset="4">
          <span>{{ formInfo.all }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.work }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.one }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.two }}</span>
        </el-col>
        <el-col :span="3">
          <span>{{ formInfo.three }}</span>
        </el-col>
      </el-row>
    </div>
    <el-table
      border
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <el-table-column
        prop="ID"
        label="序号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ROAD"
        label="道路名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ROADLEVEL"
        label="道路等级"
        align="center"
      ></el-table-column>
      <el-table-column prop="ROADLENGTH" label="道路长度"></el-table-column>
      <el-table-column prop="AREA" label="道路面积"></el-table-column>
      <el-table-column prop="COMPANY" label="作业公司"></el-table-column>
      <el-table-column prop="SINGLE" label="是否单行路"></el-table-column>
      <el-table-column
        prop="LWORK"
        label="全天作业次数"
      ></el-table-column>
      <el-table-column
        prop="LC"
        label="标准全天作业次数"
      ></el-table-column>
      <el-table-column
        prop="SC"
        label="清洗作业次数"
      ></el-table-column>
      <el-table-column prop="ZWORK" label="标准清洗作业次数"></el-table-column>
      <el-table-column prop="ZC" label="洗扫作业次数"></el-table-column>
      <el-table-column prop="FWORK" label="标准洗扫次数"></el-table-column>
      <!-- <el-table-column prop="FC" label="反向作业次数"></el-table-column> -->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import "@/assets/css/common.css";
import { formatDate } from "@/common/js/date.js";
import export2Excel from "@/utils/exportExcel/index.js";
export default {
  data() {
    return {
      currentPage: 1, //初始页
      pageSize: 10, //    每页的数据
      formInfo: {
        all: "",
        work: "",
        one: "",
        two: "",
        three: "",
      },
      form: {
        roadName: "",
        radioData: "日",
        valueDay: formatDate(
          new Date(new Date() - 3600 * 1000 * 24),
          "yyyy-MM-dd"
        ),
        valueMonth: "",
      },
      tableData: [],
      originalData: [],
      exportExcelData: [],
      groupingList: [],
      CLIENT_GROUP_NAME: "",
    };
  },
  created() {
    this.getGroupingList();
  },
  methods: {
    // 获得分组列表
    async getGroupingList() {
      var url =
        "Vehicle/GetClientInfo?client_no=" + localStorage.getItem("CLIENT_NO"); // zxdata
      let { data } = await this.$Http.get(url);
      if (localStorage.getItem("CLIENT_NO") == '00000') {
        this.groupingList = data.slice(10);
      } else {
        this.groupingList = data;
      }
      this.CLIENT_GROUP_NAME = this.groupingList[0].CLIENT_GROUP_NAME;
      this.getlistdata();
    },
    async getlistdata() {
      this.currentPage = 1;
      var date = "";
      if (this.form.radioData === "日") {
        date = this.form.valueDay;
      }
      if (this.form.radioData === "月") {
        date = this.form.valueMonth;
      }
      //Vehicle/GetRoadInfoWorkWinter?WORKDATE=2025-01-02&DISTRICT=宁河区
      var url =
        "Vehicle/GetRoadInfoNoWorkOut10Test?DISTRICT=" +
        this.CLIENT_GROUP_NAME +
        "&WORKDATE=" +
        date;
      const { data } = await this.$Http.get(url);
      this.formInfo.all = data.Info[0];
      this.formInfo.work = data.Info[1];
      this.formInfo.one = data.Info[2];
      this.formInfo.two = data.Info[3];
      this.formInfo.three = data.Info[4];

      this.tableData = data.List;
      this.tableData.shift();
      if (this.form.roadName != '') this.tableData = this.tableData.filter(item => item.ROAD.includes(this.form.roadName))
    },
    // 导出Excel
    exportExcel() {
      let excelName = "未达标道路统计表";
      const tHeader = [
        "序号",
        "道路名称",
        "道路等级",
        "道路长度",
        "道路面积",
        "作业公司",
        "是否单行路",
        "全天作业次数",
        "标准全天作业次数",
        "清洗作业次数",
        "标准清洗作业次数",
        "洗扫作业次数",
        "标准洗扫次数",
        // "反向作业次数"
      ];
      const filterVal = [
        "ID",
        "ROAD",
        "ROADLEVEL",
        "ROADLENGTH",
        "AREA",
        "COMPANY",
        "SINGLE",
        "LWORK",
        "LC",
        "SC",
        "ZWORK",
        "ZC",
        "FWORK",
        // "FC",
      ];
      export2Excel(tHeader, filterVal, this.tableData, excelName);
    },
    //详情
    handleEdit(index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange(currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      console.log(this.pageSize);
    },
  },
};
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>